package com.longcai.controller.jd;


import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.JdException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.NTbkItem;
import com.taobao.api.domain.NTbkOrder;
import com.taobao.api.internal.util.StringUtils;
import com.taobao.api.request.TbkItemGetRequest;
import com.taobao.api.request.TbkItemInfoGetRequest;
import com.taobao.api.request.TbkOrderGetRequest;
import com.taobao.api.response.TbkItemGetResponse;
import com.taobao.api.response.TbkItemInfoGetResponse;
import com.taobao.api.response.TbkOrderGetResponse;

import jd.union.open.category.goods.get.request.CategoryReq;
import jd.union.open.category.goods.get.request.UnionOpenCategoryGoodsGetRequest;
import jd.union.open.category.goods.get.response.UnionOpenCategoryGoodsGetResponse;
import jd.union.open.coupon.query.request.UnionOpenCouponQueryRequest;
import jd.union.open.coupon.query.response.CouponResp;
import jd.union.open.coupon.query.response.UnionOpenCouponQueryResponse;
import jd.union.open.goods.jingfen.query.request.JFGoodsReq;
import jd.union.open.goods.jingfen.query.request.UnionOpenGoodsJingfenQueryRequest;
import jd.union.open.goods.jingfen.query.response.ImageInfo;
import jd.union.open.goods.jingfen.query.response.JFGoodsResp;
import jd.union.open.goods.jingfen.query.response.UnionOpenGoodsJingfenQueryResponse;
import jd.union.open.goods.jingfen.query.response.UrlInfo;
import jd.union.open.goods.query.request.GoodsReq;
import jd.union.open.goods.query.request.UnionOpenGoodsQueryRequest;
import jd.union.open.goods.query.response.GoodsResp;
import jd.union.open.goods.query.response.UnionOpenGoodsQueryResponse;

import java.util.List;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 平台头条 前端控制器
 * </p>
 *
 * @author LWK
 * @since 2019-03-20
 */
@Controller
@RequestMapping("/homeQuery")
public class HomeQueryController {
	
	//京东
//   public static void main(String[] args) {
//	   try {
//关键词商品查询
//		   String SERVER_URL = "https://router.jd.com/api";
//		   String appKey = "31268b240a174e21b684e1bab5162e6c";
//		   String appSecret ="b62844ab58c546f0aa0532ba8bd1f1dc";
//		   String accessToken = "";
//
//		   JdClient client=new DefaultJdClient(SERVER_URL,accessToken,appKey,appSecret); 
//
//		   UnionOpenGoodsQueryRequest request = new UnionOpenGoodsQueryRequest();
//		   GoodsReq goodsReq = new GoodsReq();
//		   goodsReq.setSkuIds(new Long[]{6877440L,844529L});
//
//		   request.setGoodsReqDTO(goodsReq);
//		   UnionOpenGoodsQueryResponse response = client.execute(request);
//		   String SERVER_URL = "https://router.jd.com/api";
//		   String appKey = "31268b240a174e21b684e1bab5162e6c";
//		   String appSecret ="b62844ab58c546f0aa0532ba8bd1f1dc";
//		   String accessToken = "";
//	
//		   JdClient client=new DefaultJdClient(SERVER_URL,accessToken,appKey,appSecret); 
	
//		   UnionOpenCouponQueryRequest request = new UnionOpenCouponQueryRequest();
//		   request.setCouponUrls(new String[]{"http://coupon.jd.com/ilink/couponActiveFront/front_index.action?key=61c19ff15ceb450c8d801c50f729069d&roleId=7290729&to=jyhbj.jd.hk"});
//		   UnionOpenCouponQueryResponse  response = client.execute(request);
		   
//		   UnionOpenGoodsJingfenQueryRequest request = new UnionOpenGoodsJingfenQueryRequest();
//		   JFGoodsReq goodsReq = new JFGoodsReq();
//		   goodsReq.setEliteId(11);
//		   request.setGoodsReq(goodsReq);
//		   UnionOpenGoodsJingfenQueryResponse  response = client.execute(request);
//		   
//		   System.out.println("返回状态："+response.getCode());
//		   System.out.println("返回结果："+response.getMessage());
//		   JFGoodsResp[] data = response.getData();
//		   for (JFGoodsResp jfGoodsResp : data) {
//			   ImageInfo[] imageInfo = jfGoodsResp.getImageInfo();
//			   System.out.println(jfGoodsResp.getMaterialUrl());
//			   for (ImageInfo imageInfo2 : imageInfo) {
//				   UrlInfo[] imageList = imageInfo2.getImageList();
//				   for (UrlInfo urlInfo : imageList) {
//					   String url = urlInfo.getUrl();
//					   System.out.println("返回数据："+url);
//				   }
//				   System.out.println("....................");
//			   }
//			   System.out.println("----------------------");  
//		}
//		   
//		   
//		   
//	   } catch (JdException e) {
//		   // TODO Auto-generated catch block
//		   e.printStackTrace();
//	}
//   }
	//淘宝
	public static void main(String[] args) {
		try{
			TaobaoClient client = new DefaultTaobaoClient("https://eco.taobao.com/router/rest", "25920036", "6a3c92d5ba72654ec51a5bcc28c273d8");
//			TbkItemGetRequest req = new TbkItemGetRequest();
//			req.setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");
//			req.setQ("女装");
//			req.setCat("16,18");
//			req.setItemloc("杭州");
//			req.setSort("tk_rate_des");
//			req.setIsTmall(false);
//			req.setIsOverseas(false);
////			req.setStartPrice(10L);
////			req.setEndPrice(10L);
////			req.setStartTkRate(123L);
////			req.setEndTkRate(123L);
////			req.setPlatform(1L);
////			req.setPageNo(123L);
////			req.setPageSize(20L);
//			TbkItemGetResponse response = client.execute(req);
//			System.out.println("返回状态："+response.getCode());
//			   System.out.println("返回结果："+response.getMessage());
//			   List<NTbkItem> results = response.getResults();
//			   for (NTbkItem jfGoodsResp : results) {
//				   System.out.println("返回数据："+jfGoodsResp.getTitle()+"id为"+jfGoodsResp.getNumIid());
//			}
//			TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
//			req.setNumIids("581844121161");
//			req.setPlatform(1L);
//			req.setIp("11.22.33.43");
//			TbkItemInfoGetResponse rsp = client.execute(req);
//			String body = rsp.getBody();
//			JSONObject obj = (JSONObject)JSONObject.parse(body);
//			JSONObject object = (JSONObject)obj.get("tbk_item_info_get_response");
//			JSONObject object2 = (JSONObject)object.get("results");
//			JSONArray object3 = (JSONArray)object2.get("n_tbk_item");
//			for (Object object4 : object3) {
//				JSONObject o = (JSONObject)object4;
//				System.out.println(o.get("cat_leaf_name"));
//			}
//			System.out.println(rsp.getBody());
			TbkOrderGetRequest req = new TbkOrderGetRequest();
			req.setFields("tb_trade_parent_id,tb_trade_id,num_iid,item_title,item_num,price,pay_price,seller_nick,seller_shop_title,commission,commission_rate,unid,create_time,earning_time,tk3rd_pub_id,tk3rd_site_id,tk3rd_adzone_id,relation_id,tb_trade_parent_id,tb_trade_id,num_iid,item_title,item_num,price,pay_price,seller_nick,seller_shop_title,commission,commission_rate,unid,create_time,earning_time,tk3rd_pub_id,tk3rd_site_id,tk3rd_adzone_id,special_id,click_time");
			req.setStartTime(StringUtils.parseDateTime("2016-05-23 12:18:22"));
			req.setSpan(600L);
			req.setPageNo(1L);
			req.setPageSize(20L);
			req.setTkStatus(1L);
			req.setOrderQueryType("settle_time");
			req.setOrderScene(1L);
			req.setOrderCountType(1L);
			TbkOrderGetResponse rsp = client.execute(req);
			List<NTbkOrder> results = rsp.getResults();
			for (NTbkOrder nTbkOrder : results) {
				String unid = nTbkOrder.getUnid();
			}
			System.out.println(rsp.getBody());
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

